<template>
	<view>
		<view style="padding: 42upx;margin: 12upx;" class="bg">

			<text class="num" style="font-size: 32upx;color: #000000;margin-bottom: 10px">
				<text style="font-size: 32upx;font-weight: bold;color: #000000;margin-right:10upx;">当前等级</text>
				<text style="font-size: 30upx;font-weight: bold;margin-right:6upx;"> • VIP</text>
				<text style="font-size: 50upx;font-weight: bold;font-weight: bold;">{{ dengji }}</text>
			</text>
			<view style="font-size: 28upx;margin-top: 32upx;color: #000000;">{{ dengjides }}</view>
		</view>
		<view style="text-align: left;color: #333333;font-size: 28upx;">
			<view style="margin-top: 16upx;background: #FFFFFF;border-radius: 16upx;padding: 26upx;margin: 12upx;">
				<view style="font-size: 32upx;font-weight: bold;margin-bottom: 16upx;">邀请规则</view>
				<view>1、每成功邀请1位好友提升1级，最高{{ invitatioNum }}级每级对应相应的返现比例</view>
				<view style="margin-top: 8upx">2、邀请成功可享受直属好友佣金{{twoMoney }}%提成</view>
				<view style="margin-top: 8upx" v-if="setting==2">3、已邀请成功的好友再邀请好友可享受非直属好友佣金{{ threeMoney }}%提成</view>
			</view>
			<view style="margin-top: 16upx;background: #FFFFFF;border-radius: 16upx;padding: 26upx;margin: 12upx;">
				<view style="font-size: 32upx;font-weight: bold;margin-bottom: 16upx;margin-top: 16upx;">邀请方式</view>
				<!-- <view>1、点击下方【生成邀请海报】选择任意免单商品生成海报，将海报分享好友、群或朋友圈，让好友扫码即可升级</view> -->
				<view style="margin-top: 8upx;">点击下方【分享邀请链接】生成专属推广链接，分享好友、群，让好友注册即可升级</view>
			</view>
		</view>
		<view style="display: flex;margin-top: 64upx;margin-left: 16upx;margin-right: 16upx;">
			<!-- <view @click="productHaibao()" style="margin-right: 32upx;text-align: center;width: 50%;background: #FFCB49;font-size: 32upx;color: white;border-radius: 20upx;height: 80upx;line-height: 80upx">
				生成邀请海报
			</view> -->
			<!-- #ifdef H5 -->
			<view @click="share()" style="text-align: center;width: 100%;background: #ED3113;font-size: 32upx;color: white;border-radius: 20upx;height: 80upx;line-height: 80upx">
				分享邀请链接
			</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view @click="shareWeiXin()" style="text-align: center;width: 50%;background: #ED3113;font-size: 32upx;color: white;border-radius: 20upx;height: 80upx;line-height: 80upx">
				分享邀请链接
			</view>
			<!-- #endif -->
		</view>
	</view>
</template>
<script>
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
	import appShare from '@/utils/share.js';
	export default {
		components: {
			tkiQrcode
		},
		data() {
			return {
				setting: 1,
				modalName: '',
				totalMoney: '0',
				dengji: 0,
				itemendprice: '识别二维码免费领取',
				tuiguang: '给你说个京东、淘宝、拼多多买东西省钱工具叫优集聚！\n买东西能货比三家买不了吃亏买不了上当\n我用好久了买东西不但能领券还能返现！\n这一年半载我都省下一大半了！\n点链接可以看看\n',
				itemtitle: '',
				relationId: '',
				invitationCode:'',
				itemprice: '',
				erweima: '',
				itempic: '',
				twoMoney: '',
				threeMoney: '',
				url: '',
				invitatioNum: 0,
				dengjides: '生成海报'
			};
		},
		onLoad() {
			this.getSetting();
			let number = this.$queue.invitaionNum();
			this.twoMoney = parseFloat(this.$queue.teamMoney()) * 100;
			this.threeMoney = parseFloat(this.$queue.threeMoney()) * 100;
			this.invitatioNum = parseInt(number);
		},
		onShow() {
			let relationId = this.$queue.getData('relation_id');
			if (relationId) {
				this.relationId = relationId;

				// #ifndef H5
				if (this.invitationCode) {
					this.url = this.$queue.publicYuMing() + '/pages/member/download?relationId=' + this.$queue.getData(
						'relation_id') + '&invitationCode=' + this.invitationCode;
				
				} else {
					this.url = this.$queue.publicYuMing() + '/pages/member/download?relationId=' + this.$queue.getData(
						'relation_id');
				
				}
				//#endif
				// #ifdef H5
				this.url = this.$queue.publicYuMing() + '/?invitation=' + relationId;
				//#endif
			}
			let userId = this.$queue.getData('userId');
			if (userId) {
				this.getUserInfo(userId);
			}
		},
		methods: {
			getSetting() {
				this.$Request.getT('/common/type/91').then(res => {
					if (res.status == 0) {
						if (res.data && res.data.value) {
							this.setting = res.data.value
						}
					}
				});
			},
			productHaibao() {
				uni.navigateTo({
					url: '/pages/share/product'
				});
			},
			yaoqing() {
				uni.navigateTo({
					url: '/pages/member/yaoqing'
				});
			},
			hideModal() {
				this.modalName = null;
			},

			shareWeiXin() {
				let relationId = this.$queue.getData('relation_id');
				let shareData = {
					shareUrl: this.url,
					shareTitle: '邀请你加入优集聚！先领券，再购物，更划算！',
					shareContent: '邀请码：' + this.invitationCode + '，复制宝贝标题，在优集聚搜索就可以领高额优惠券啦！',
					shareImg: this.$queue.publicYuMing() + '/logo.png',
					type: 0
				};
				appShare(shareData, res => {
					console.log('分享成功回调', res);
				});
			},
			yong() {
				this.$Request.getT('/common/type/43').then(res => {
					if (res.status == 0) {


					}
				});
			},
			share() {
				this.sharurl();
			},
			getUserInfo(userId) {
				this.$Request.getT('/user/' + userId).then(res => {
					if (res.status === 0) {
						this.invitationCode = res.data.invitationCode;
						if (res.data.gradeDes) {
							this.dengji = res.data.gradeIndex;
						} else {
							this.dengji = 0;
						}
						if (res.data.gradeNumber) {
							if (res.data.gradeNumber == '还可邀请0人') {
								this.dengjides = '已到达最高等级';
							} else {
								this.dengjides = res.data.gradeNumber;
							}
						} else {
							this.dengjides = '还可邀请' + this.invitatioNum + '人';
						}
					}
				});
			},
			sharurl() {
				let that = this;
				
				uni.showModal({
					title: '链接推广',
					content: this.tuiguang + this.url,
					showCancel: true,
					cancelText: '关闭',
					confirmText: '一键复制',
					success: res => {
						if (res.confirm) {
							uni.setClipboardData({
								data: this.tuiguang + this.url,
								success: function() {
									console.log('success');
									that.$queue.showToast('复制成功');
								}
							});
						}
					}
				});
				
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import '../../static/css/index.css';

	.bg {
		background-image: url(../../static/img/my/VIP.png);
		background-repeat: round;
		background-size: 100%;
	}
</style>
